<template>

  <bodyWrap :isShow="bodyShow">
    <div slot="body" v-if="bodyShow">

      <!--选题列表-->
      <div class="d-item-wrap" v-if="infoListLen">
        <div class="d-title"></div>
        <div class="d-content">
          <ul>
            <li class="item" v-for="item in infoList" v-if="item.title">
              <div class="title">
                <i class="iconfont icon-xing" v-if="item.isImportant == 1"></i>
                {{item.title}}
              </div>
              <div class="news-s">
                <div class="content">
                  报送单位：{{item.sendDeptName}}
                </div>
              </div>
              <div class="news-s">
                <div class="content">
                  报送人：{{item.sendUserName}}
                </div>
                <div class="btn-d" @tap="checkNews(item)">
                  查看详情
                </div>
              </div>
              <input type="checkbox" class="check-input" :value="item" v-model="checked">
              <div>
                <div></div>
              </div>
            </li>
          </ul>
        </div>
      </div>

      <no-data v-if="!infoListLen"></no-data>
      <transition name="slideRight">
        <router-view></router-view>
      </transition>
    </div>
  </bodyWrap>

</template>

<script>
  import noData from "./noMoreData.vue"

  export default {

    data() {
      return {
        infoList: [],
        headerRightType: null,
        headerFlag: null,
        checked: [],
        bodyShow: false
      }
    },
    methods: {
      init() {
        let data = {
          type: -1,
          pageIndex: 1,
          pageSize: 1000,
          bulltinStatus: "0,1",
          userId: _data.userInfo.userId
        };
        _ajax.noLoading(_ajaxUrls.infoList.url,
          data,
          (ajData) => {

            this.infoList = ajData.data.list;

            this.bodyShow = true;

          }, _ajaxUrls.infoList.type);
      },
      checkNews(item) {
        _methods.goPath(`/tnDetail/infoList/infoDetail?id=${item.messageId}&type=2`);
      },
      addNews() {

        let messageIds = this.checked.map((i)=>{

          return i.messageId;

        }).join(",");

        let data = {
          messageIds,
          processId:_data.todayNewsDetail.processId,
        };

        _ajax.confirmWithLoading(_ajaxUrls.addInfoTodayNews.url + data.processId,
          data,
          () => {
            this.init();
            _data.bus.$emit("addNews",this.checked);
            this.checked = [];
            _alert.alert(() => {
            }, "添加成功");
          },
          _ajaxUrls.addInfoTodayNews.type,
          "是否确认添加?")
      },
    },
    components: {
      noData
    },
    computed: {
      infoListLen() {
        return this.infoList.length;
      }
    },
    created() {
      this.headerRightType = this.$store.state.headerRightType;
      this.headerFlag = this.$store.state.showFlag;
      _methods.headerTitleChange(11);
      this.$store.commit("_headerRightType", {
        val: 11,
        txt: "确定"
      });
      this.init();
    },
    mounted() {
      let self = this;
      _data.busInit.on_(() => {
        self.addNews();
      });
    },
    beforeDestroy() {
      _data.busInit.off_();
      this.$store.commit("_headerRightType", this.headerRightType);
      _methods.headerTitleChange(this.headerFlag, true);
    }

  }

</script>
